home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / benchmarks / open / RCS / open.c,v < prev   
Encoding:
Text File  |  1989-09-14  |  2.4 KB  |  107 lines

  1. head     1.1;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    ; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 1.1
  10. date     89.09.13.20.48.43;  author ouster;  state Exp;
  11. branches ;
  12. next     ;
  13.  
  14.  
  15. desc
  16. @@
  17.  
  18.  
  19.  
  20. 1.1
  21. log
  22. @Initial revision
  23. @
  24. text
  25. @/* 
  26.  * open.c --
  27.  *
  28.  *    This program is a stand-alone benchmark that measures
  29.  *    the cost of opening and closing a file.
  30.  *
  31.  *    open fileName count
  32.  *
  33.  *    where "fileName" is the name of the file to open and
  34.  *    close and "count" tells how many open/close pairs to
  35.  *    execute.
  36.  *
  37.  * Copyright 1989 Regents of the University of California.
  38.  * Permission to use, copy, modify, and distribute this
  39.  * software and its documentation for any purpose and without
  40.  * fee is hereby granted, provided that the above copyright
  41.  * notice appear in all copies.  The University of California
  42.  * makes no representations about the suitability of this
  43.  * software for any purpose.  It is provided "as is" without
  44.  * express or implied warranty.
  45.  */
  46.  
  47. #ifndef lint
  48. static char rcsid[] = "$Header: protoPub.c,v 1.3 87/01/04 17:28:56 andrew Exp $ SPRITE (Berkeley)";
  49. #endif not lint
  50.  
  51.  
  52. #include <stdio.h>
  53. #include <sys/file.h>
  54. #include <sys/time.h>
  55. #include <sys/resource.h>
  56.  
  57. main(argc, argv)
  58. int argc;
  59. char **argv;
  60. {
  61.     int repeats, fd, count;
  62.     double msPer, micros;
  63.     struct rusage begin ,end;
  64.     struct timeval start, stop;
  65.     struct timezone tz;
  66.  
  67.     if (argc != 3) {
  68.     fprintf(stderr, "Usage:  %s fileName count\n",
  69.         argv[0]);
  70.     exit(1);
  71.     }
  72.     repeats = atoi(argv[2]);
  73.  
  74. #ifdef GETRUSAGE
  75.     getrusage(RUSAGE_SELF, &begin);
  76. #else
  77.     gettimeofday(&start, (struct timezone *) NULL);
  78. #endif
  79.  
  80.     for (count = 0 ; count < repeats; count++) {
  81.     fd = open(argv[1], O_RDONLY, 0);
  82.     if (fd < 0) {
  83.         fprintf(stderr, "Couldn't open %s.\n", argv[1]);
  84.         exit(1);
  85.     }
  86.     if (close(fd) != 0) {
  87.         fprintf(stderr, "Error closing %s.\n",
  88.             argv[1]);
  89.         exit(1);
  90.     }
  91.     }
  92. #ifdef GETRUSAGE
  93.     getrusage(RUSAGE_SELF, &end);
  94.     micros = (end.ru_utime.tv_sec + end.ru_stime.tv_sec
  95.         - begin.ru_utime.tv_sec - begin.ru_stime.tv_sec)*1000000
  96.         + (end.ru_utime.tv_usec - begin.ru_utime.tv_usec)
  97.         + (end.ru_stime.tv_usec - begin.ru_stime.tv_usec);
  98. #else
  99.     gettimeofday(&stop, (struct timezone *) NULL);
  100.     micros = 1000000*(stop.tv_sec - start.tv_sec)
  101.         + stop.tv_usec - start.tv_usec;
  102. #endif
  103.     msPer = (micros/repeats/1000.0);
  104.     printf("Time per open/close pair: %.2f milliseconds\n", msPer);
  105. }
  106. @
  107.